package com.ygqh.baby.model;

import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.List;

public class PrizeItem {

	private Integer index;
	private Type type;
	private String relationCode;
	private String content;
	private BigDecimal rate;
	// 限制数量
	private Integer limitCount;

	// 抽奖多少次完成
	private Integer drawCount;

	private String imgUrl;
	// 剩余抽奖次数
	private int lastCount;

	private List<PrizeItemRule> ruleList;

	private BigDecimal thisRate;
	private BigDecimal totalRate;

	private String coupon;

	private Boolean falg = Boolean.FALSE;

	private BigDecimal rateForNewCustom;

	public Boolean getFalg() {
		return falg;
	}

	public void setFalg(Boolean falg) {
		this.falg = falg;
	}

	public BigDecimal getTotalRate() {
		return totalRate;
	}

	public void setTotalRate(BigDecimal totalRate) {
		this.totalRate = totalRate;
	}

	public Integer getDrawCount() {
		return drawCount;
	}

	public void setDrawCount(Integer drawCount) {
		this.drawCount = drawCount;
	}

	public String getCoupon() {
		return coupon;
	}

	public void setCoupon(String coupon) {
		this.coupon = coupon;
	}

	public BigDecimal getThisRate() {
		return thisRate;
	}

	public void setThisRate(BigDecimal thisRate) {
		if (thisRate != null) {

			thisRate = thisRate.setScale(2, BigDecimal.ROUND_HALF_UP);
		}
		this.thisRate = thisRate;
	}

	public List<PrizeItemRule> getRuleList() {
		return ruleList;
	}

	public void setRuleList(List<PrizeItemRule> ruleList) {
		this.ruleList = ruleList;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

	public int getLastCount() {
		return lastCount;
	}

	public void setLastCount(int lastCount) {
		this.lastCount = lastCount;
	}

	public PrizeItem() {
		super();
	}

	public Boolean isLimit() {
		if (limitCount != null && limitCount >= 0) {
			return true;
		}
		return false;
	}

	public String getKey(String baseKey) {
		if (StringUtils.isEmpty(baseKey)) {
			baseKey = "";
		}

		return baseKey + "-" + relationCode;
	}

	public Integer getLimitCount() {
		return limitCount;
	}

	public void setLimitCount(Integer limitCount) {
		this.limitCount = limitCount;
	}

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public Type getType() {
		return type;
	}

	public String getTypeStr() {
		if (type == null) {
			return null;
		}
		return type.name();
	}

	public String getTypeName() {
		if (type == null) {
			return null;
		}
		return type.getTitle();
	}

	public void setType(Type type) {
		this.type = type;
	}

	public String getRelationCode() {
		return relationCode;
	}

	public void setRelationCode(String relationCode) {
		this.relationCode = relationCode;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public BigDecimal getRate() {
		return rate;
	}

	public void setRate(BigDecimal rate) {
		this.rate = rate;
	}

	public BigDecimal getRateForNewCustom() {
		return rateForNewCustom;
	}

	public void setRateForNewCustom(BigDecimal rateForNewCustom) {
		this.rateForNewCustom = rateForNewCustom == null ? rate : rateForNewCustom;
	}

	public BigDecimal getRate(boolean newCustom) {
		return newCustom ? rateForNewCustom : rate;
	}

	public enum Type {
		Coupon(0, "优惠券"), Balance(0, "成长基金"), Goods(0, "实物"), Card(0, "卡券"), Cash(0, "现金红包");
		/** 状态码 */
		private Integer code;
		/** 状态名称 */
		private String title;

		Type(Integer code, String title) {
			this.code = code;
			this.title = title;
		}

		public Integer getCode() {
			return code;
		}

		public void setCode(Integer code) {
			this.code = code;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}
	}

	@Override
	public String toString() {
		return "PrizeItem{" +
				"index=" + index +
				", type=" + type +
				", relationCode='" + relationCode + '\'' +
				", content='" + content + '\'' +
				", rate=" + rate +
				", limitCount=" + limitCount +
				", drawCount=" + drawCount +
				", imgUrl='" + imgUrl + '\'' +
				", lastCount=" + lastCount +
				", ruleList=" + ruleList +
				", thisRate=" + thisRate +
				", totalRate=" + totalRate +
				", coupon='" + coupon + '\'' +
				", falg=" + falg +
				", rateForNewCustom=" + rateForNewCustom +
				'}';
	}
}
